package com.waidi.clothespad.fragment;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.Nullable;

import android.support.v7.app.ActionBar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.waidi.clothespad.R;
import com.waidi.clothespad.common.Config;
import com.waidi.clothespad.common.MessageToUi;
import com.waidi.clothespad.common.MyToast;
import com.waidi.clothespad.ui.WaitDialog;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;



/**
 * Created by Administrator on 2017/4/26.
 */

public class FragHouProduct extends Fragment {
    private static final String TAG = "FragHouProduct";

    private View view;
    public Context context;
    public  HouDaoGongYI handler;
    PopupWindow popupWindow;

    private TextView tv_orderid = null;
    private TextView tv_styleid =null;
    private TextView tv_num = null;
    private TextView tv_line = null;



    private ViewPager viewPager;
    private int[] imageResIds;
    private ArrayList<ImageView> imageViewList;
    private ArrayList<String> contentList;

    private ArrayList<String> nameList;
    private ArrayList<String> urlList;
    private ArrayList<Drawable> drawableList;

    private DisplayImageOptions options;

    private MyAdapter myAdapter;
    private LinearLayout ll_point_container;
    private String[] contentDescs;
    private TextView tv_desc;
    private int previousSelectedPosition = 0;
    boolean isRunning = false;
    private WaitDialog waitDialog =null;
    private static boolean loading = false;
    private boolean onDetach = false;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.frag_houdao_info, container, false);
        onDetach = false;
        return view;

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        context = getActivity();
        handler = new FragHouProduct.HouDaoGongYI();

        initParam();
        initElem();

    }
    private void initWaitDialog()
    {
        waitDialog = new WaitDialog(context);
        waitDialog.setText("loading...");
    }

    public void initParam() {

        initWaitDialog();

/*      popupWindow = new PopupWindow(contentview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popupWindow.setBackgroundDrawable(new ColorDrawable());*/

/*        ptime_s = (EditText)contentview.findViewById(R.id.ptime_s);
        ptime_e = (EditText)contentview.findViewById(R.id.ptime_e);
        ptime_s.setInputType(InputType.TYPE_NULL);
        ptime_e.setInputType(InputType.TYPE_NULL);*/

      //  initEditTextEvent(contentview);

        // 初始化布局 View视图
        initContentview(view);

        // Model数据
        initData();

        // Controller 控制器
        initAdapter();



        // 开启轮询
        new Thread(){
            public void run() {
                isRunning = true;
                while(isRunning){
                    try
                    {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Message msg1;
                    msg1=handler.obtainMessage();//每发送一次都要重新获取
                    msg1.arg1 = 1;
                    msg1.obj = 0;
                    handler.sendMessage(msg1);
                }
            };
        }.start();
    }

    public void initContentview(View contentview)
    {
        tv_orderid = (TextView) contentview.findViewById(R.id.pd_order_id);
        tv_styleid = (TextView) contentview.findViewById(R.id.pd_style_id);
        tv_num = (TextView) contentview.findViewById(R.id.pd_order_number);
        tv_line = (TextView) contentview.findViewById(R.id.pd_order_line);

        viewPager = (ViewPager) contentview.findViewById(R.id.viewpager);
        //viewPager.setOnPageChangeListener(this);// 设置页面更新监听
//		viewPager.setOffscreenPageLimit(1);// 左右各保留几个对象
        ll_point_container = (LinearLayout) contentview.findViewById(R.id.ll_point_container);
        tv_desc = (TextView) contentview.findViewById(R.id.tv_desc);


        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener()
        {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                // 新的条目被选中时调用
                int newPosition = position % imageViewList.size();
                System.out.println("onPageSelected: " + position+" size: "+imageViewList.size()+" # "+newPosition);
                //设置文本
                if(contentList.size()>newPosition) {
                    tv_desc.setText(contentList.get(newPosition));
                    System.out.println("onPageSelected-2: " + contentList.get(newPosition));
                }

//		for (int i = 0; i < ll_point_container.getChildCount(); i++) {
//			View childAt = ll_point_container.getChildAt(position);
//			childAt.setEnabled(position == i);
//		}
                // 把之前的禁用, 把最新的启用, 更新指示器
                ll_point_container.getChildAt(previousSelectedPosition).setEnabled(false);
                ll_point_container.getChildAt(newPosition).setEnabled(true);
                // 记录之前的位置
                previousSelectedPosition  = newPosition;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
    //刷卡后请求数据
    public void dpsgetProcedureInfo(String orderid,String styleid,String num,String line)
    {
        if(loading == true)
        {
            Log.i(TAG,"当前有刷卡请求正在进行。。。");
           // return;
        }

        tv_orderid.setText(orderid);
        tv_styleid.setText(styleid);
        tv_num.setText(num);
        tv_line.setText(line);

        if(Config.qrCodeInfo.location.length()!=6)
        {
            MyToast.showToast(context,"设备二维码信息未绑定或绑定错误？");
            return;
        }
        if(Config.rfidWorkerInfo.workername.length()==0)
        {
            MyToast.showToast(context,"请先刷卡登录，获取工艺信息?");
            return;
        }

        Config A = new Config(context);
        Config.DpsInterface dpsInterface = A.new DpsInterface(Config.devConfig.web_addr);

        String path =dpsInterface.houdao_productInfo;
        String url=path+"&po="+orderid +"&workNum="+Config.rfidWorkerInfo.workernum;;
        httploadProcedureInfo thread = new  httploadProcedureInfo(handler,context,url);

        waitDialog.show();//loading......
        thread.start();
    }

    public class httploadProcedureInfo extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public httploadProcedureInfo(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run() {

            Message msg1;
            String result = "";
            HttpClient httpCient = new DefaultHttpClient();
            httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,3000);//连接时间
            httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间
            HttpGet httpGet = new HttpGet(Url);
            int code = -1;
            try {
                Log.i(TAG, Url);
                //loading = true;
                HttpResponse response = httpCient.execute(httpGet);
                //loading = false;
                waitDialog.dismiss();

                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get orderinfo reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200) {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                }
                else
                {
                    String err = "请求返回: "+code;
                    new MessageToUi().send(20,"exception",err,handler0);
                    return;
                }
            }
            catch (Exception e)
            {
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                waitDialog.dismiss();
                new MessageToUi().send(20,"exception",e.toString(),handler0);
                return;
            }
            try
            {
                JSONObject jsonObj = new JSONObject(result);
                if (jsonObj == null)
                    return;
                else
                {
                    //dps 后道
                    if(jsonObj.has("error")==true)
                    {
                        JSONObject error = jsonObj.optJSONObject("error");
                        String message = error.optString("message");
                        new MessageToUi().send(20,"exception",message,handler0);
                        return;
                    }
                    else
                    {
                        if (jsonObj.has("data") == true)
                        {
                            JSONObject j_dpsdata = jsonObj.optJSONObject("data");
                            JSONArray dpspicArray = j_dpsdata.getJSONArray("urlList");
                            if (dpspicArray != null) {
                                int size = dpspicArray.length();
                                if (size > 0)
                                {
                                    urlList.clear();
                                    for (int i = 0; i < size; i++)
                                    {
                                        String picurl = dpspicArray.optString(i);
                                        if (picurl.length() != 0) {
                                            Log.i(TAG, picurl);
                                            urlList.add(picurl);
                                        }
                                        // Log.i(TAG,"pic0 url size:"+Integer.toString(urlList.size()));
                                    }
                                }else
                                {
                                    new MessageToUi().send(20,"exception","改站位没有工序",handler0);
                                    return;
                                }
                            }
                            JSONArray dpsnameArray = j_dpsdata.getJSONArray("nameList");
                            if (dpsnameArray != null) {
                                int size = dpsnameArray.length();
                                if (size > 0) {
                                    nameList.clear();
                                    for (int k = 0; k < size; k++)
                                    {
                                        String name = dpsnameArray.optString(k);
                                        if (name.length() != 0) {
                                            Log.i(TAG, name);
                                            nameList.add(name);
                                        }
                                    }
                                } else {
                                    String info = "改站位对应工艺，请至少上传一张工艺图片！";
                                    new MessageToUi().send(20,"exception",info,handler0);
                                }
                            }
                        }
                    }
                }
            }
            catch (JSONException e)
            {
                e.printStackTrace();
                new MessageToUi().send(20,"exception",e.toString(),handler0);


                return;
            }

            try
            {
                if(urlList.size()!=0)
                {
                    Log.i(TAG,"pic url size:"+Integer.toString(urlList.size()));
                    msg1=handler.obtainMessage();//每发送一次都要重新获取
                    msg1.arg1 = 21;
                    handler.sendMessage(msg1);
                    //Thread.sleep(1000);
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
                new MessageToUi().send(20,"exception",e.toString(),handler0);

                return;
            }

        }
        @Override
        public void destroy() {
            super.destroy();

            loading = false;
        }

    }


    private void loadIamge(final String imgUrl,final String picname)
    {

        Thread thread = new Thread() {
            @Override
            public void run()
            {
        try
        {
            Drawable drawable = Drawable.createFromStream(new URL(imgUrl).openStream(), picname);
            drawableList.add(drawable);
            Log.i(TAG,"图片资源数："+drawableList.size());
            Message msg1;
            msg1=handler.obtainMessage();//每发送一次都要重新获取
            msg1.arg1 = 22;
            handler.sendMessage(msg1);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
            }
        };
        thread.start();
        thread =null ;
    }

    public void initElem() {

    }
    private void initEditTextEvent(View contentview)
    {

    }

    private void showAlertDialog(String msg, final int type) {
        AlertDialog.Builder builder= new AlertDialog.Builder(context);
        builder.setTitle("注意").setMessage(msg);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                //ok
                popupWindow.dismiss(); //隐藏

            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //cancle
                popupWindow.dismiss(); //隐藏
            }

        });
        builder.show();
    }
    /**
     * 初始化要显示的数据
     */
    private void initData() {

        options = new DisplayImageOptions.Builder()
                .cacheInMemory(false)
                .cacheOnDisk(false)
                .showImageForEmptyUri(R.drawable.image_err)
                .showImageOnLoading(R.drawable.animation3)
                .showImageOnFail(R.drawable.image_err)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
/*                .displayer(new RoundedBitmapDisplayer(50))
                .displayer(new FadeInBitmapDisplayer(100))*/
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        //图片加载器ImageLoader
        //创建默认的ImageLoader配置参数
/*ImageLoaderConfiguration configuration = ImageLoaderConfiguration
                        .createDefault(context)*/

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                context)
                .memoryCacheExtraOptions(800, 480)// 缓存在内存的图片的宽和高度
                .memoryCacheSize(2 * 1024 * 1024) //缓存到内存的最大数据
                .defaultDisplayImageOptions(options).  //上面的options对象，一些属性配置
                build();
        //Initialize ImageLoader with configuration.
       ImageLoader.getInstance().init(config);



        urlList = new ArrayList<String>();
        nameList = new ArrayList<String>();
        drawableList = new ArrayList<Drawable>();

        // 图片资源id数组
        imageResIds = new int[]{R.drawable.default_0, R.drawable.default_0, R.drawable.default_0, R.drawable.default_0, R.drawable.default_0};
        // 文本描述
        contentDescs = new String[]
        {
                "订后领暗扣*2",
                "下摆订线袢*2",
                "整烫,大烫",
                "成品检验0",
                "成品检验1"
        };

        // 初始化要展示的5个ImageView
        imageViewList = new ArrayList<ImageView>();
        contentList = new ArrayList<String>();

        contentList.add(contentDescs[0]);
        contentList.add(contentDescs[1]);
        contentList.add(contentDescs[2]);
        contentList.add(contentDescs[3]);
        contentList.add(contentDescs[4]);


        ImageView imageView;
        View pointView;
        LinearLayout.LayoutParams layoutParams;
        for (int i = 0; i < imageResIds.length; i++) {
            // 初始化要显示的图片对象
            imageView = new ImageView(context);
            //imageView.setBackgroundResource(imageResIds[i]);
            imageView.setImageResource(imageResIds[i]);
            imageViewList.add(imageView);
            // 加小白点, 指示器
            pointView = new View(context);
            pointView.setBackgroundResource(R.drawable.selector_bg_point);
            layoutParams = new LinearLayout.LayoutParams(10, 10);
            if (i != 0)
                layoutParams.leftMargin = 10;
            // 设置默认所有都不可用
            pointView.setEnabled(false);
            ll_point_container.addView(pointView, layoutParams);
        }
    }
    private void initAdapter() {
        ll_point_container.getChildAt(0).setEnabled(true);

        tv_desc.setText(contentList.get(0));
        previousSelectedPosition = 0;

        // 设置适配器
        myAdapter = new MyAdapter(imageViewList);
        viewPager.setAdapter(myAdapter);
        // 默认设置到中间的某个位置
        int pos = Integer.MAX_VALUE / 2 - (Integer.MAX_VALUE / 2 % imageViewList.size());
        // 2147483647 / 2 = 1073741823 - (1073741823 % 5)

        // 刚开始的时候 把当前页面是先到最大值的一半 为了循环滑动
        int currentItem = 0;
        // 让第一个当前页是 0
        //currentItem = currentItem - ((Integer.MAX_VALUE / 2) % 4);
        viewPager.setCurrentItem(currentItem);
        delPage(0);
        delPage(0);
        delPage(0);
        //viewPager.setCurrentItem(5000000); // 设置到某个位置
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        isRunning = false;
    }
    public void adddefaultPage()
    {
        ImageView imageView;
        View pointView;
        LinearLayout.LayoutParams layoutParams;
        // 初始化要显示的图片对象
        imageView = new ImageView(context);
        imageView.setBackgroundResource(R.drawable.houdao_default);
        imageViewList.add(imageView);//为数据源添加一项数据

        myAdapter.notifyDataSetChanged();//通知UI更新*/
        // 加小白点, 指示器
        pointView = new View(context);
        pointView.setBackgroundResource(R.drawable.selector_bg_point);
        layoutParams = new LinearLayout.LayoutParams(10, 10);

        layoutParams.leftMargin = 10;
            // 设置默认所有都不可用
        pointView.setEnabled(false);
        ll_point_container.addView(pointView, layoutParams);
    }




    public void addNewImagePage(Drawable dd)
    {
        ImageView imageView;
        View pointView;
        LinearLayout.LayoutParams layoutParams;

        // 初始化要显示的图片对象
        imageView = new ImageView(context);
        imageView.setImageDrawable(dd);
        imageViewList.add(imageView);//为数据源添加一项数据

        myAdapter.notifyDataSetChanged();//通知UI更新*/
        // 加小白点, 指示器
        pointView = new View(context);
        pointView.setBackgroundResource(R.drawable.selector_bg_point);
        layoutParams = new LinearLayout.LayoutParams(10, 10);

        layoutParams.leftMargin = 10;
        // 设置默认所有都不可用
        pointView.setEnabled(false);

        ll_point_container.addView(pointView, layoutParams);
    }


    private void addUrlIamgePage(String url)
    {
        ImageView imageView;
        View pointView;
        LinearLayout.LayoutParams layoutParams;
        //初始化要显示的图片对象
        imageView = new ImageView(context);
        try {
        ImageLoader.getInstance().clearDiskCache();//清除磁盘缓存
        ImageLoader.getInstance().clearMemoryCache();//清除内存缓存

        ImageLoader.getInstance().displayImage(url, imageView,
                options);
        imageViewList.add(imageView);//为数据源添加一项数据
        myAdapter.notifyDataSetChanged();//通知UI更新*/
        // 加小白点, 指示器
        pointView = new View(context);
        pointView.setBackgroundResource(R.drawable.selector_bg_point);
        layoutParams = new LinearLayout.LayoutParams(10, 10);
        layoutParams.leftMargin = 10;
        // 设置默认所有都不可用
        pointView.setEnabled(false);
        ll_point_container.addView(pointView, layoutParams);
        }
        catch (Exception e)
        {
            Toast toast0;
            toast0 = Toast.makeText(context, "加载图片错误！", Toast.LENGTH_SHORT);
            toast0.show();


        }

    }

    /**
     * 删除当前页面
     */
    public void delPage(int position)
    {
       // int position = viewPager.getCurrentItem();//获取当前页面位置

/*        if(position>=imageViewList.size())
            return;*/
        position = position%imageViewList.size();

        imageViewList.remove(position);//删除一项数据源中的数据
        myAdapter.notifyDataSetChanged();//通知UI更新
        ll_point_container.removeViewAt(position);

    }

    public void setPage(int position,Drawable dd)
    {
        ImageView imageView;
        View pointView;
        LinearLayout.LayoutParams layoutParams;
        // 初始化要显示的图片对象
        imageView = new ImageView(context);
        imageView.setImageDrawable(dd);
        imageViewList.set(position,imageView);//为数据源添加一项数据
        myAdapter.notifyDataSetChanged();//通知UI更新*/
    }






    class MyAdapter extends PagerAdapter {

        private ArrayList<ImageView> list_view;

        public MyAdapter(ArrayList<ImageView> list_view)
        {
            this.list_view = list_view;
        }

        @Override
        public int getCount()
        {
            return list_view.size();
        }
        // 3. 指定复用的判断逻辑, 固定写法
        @Override
        public boolean isViewFromObject(View view, Object object) {
//			System.out.println("isViewFromObject: "+(view == object));
            // 当划到新的条目, 又返回来, view是否可以被复用.
            // 返回判断规则
            return view == object;
        }

        @Override
        public int getItemPosition(Object object) {
            // TODO Auto-generated method stub
            return PagerAdapter.POSITION_NONE;
        }


        // 1. 返回要显示的条目内容, 创建条目
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            System.out.println("instantiateItem初始化: " + position);
            // container: 容器: ViewPager
            // position: 当前要显示条目的位置 0 -> 4




            container.addView(list_view.get(position % list_view.size()));
            return list_view.get(position % list_view.size());




    /*        int newPosition = 0;
            if(imageViewList.size()>0)
            {
                newPosition = position % imageViewList.size();
            }
            else
                return null;

            ImageView imageView = imageViewList.get(newPosition);


            // TODO Auto-generated method stub
            //判断待添加的视图是否已存在父控件，若存在则调用removeAllViews()去除之
            ViewGroup parent = (ViewGroup) imageView.getParent();
            //Log.i("ViewPaperAdapter", parent.toString());
            if (parent != null) {
                parent.removeAllViews();
            }
            // a. 把View对象添加到container中
            container.addView(imageView);
            // b. 把View对象返回给框架, 适配器
            return imageView; // 必须重写, 否则报异常*/
        }
        // 2. 销毁条目
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            // object 要销毁的对象
            System.out.println("destroyItem销毁: " + position);
            container.removeView((View) object);

          //  container.removeView(list_view.get(position % list_view.size()));
        }
    }

    //自定义handler类

    class HouDaoGongYI extends Handler {
        @Override
        //接收别的线程的信息并处理
        public void handleMessage(Message msg) {
            Log.i("HouDaoGongYI",Integer.toString(msg.arg1));

            try {
                switch (msg.arg1) {
                    case 1:
                        //Bundle bundle0=msg.getData();
                        //System.out.println("设置当前位置: " + viewPager.getCurrentItem());
                        //viewPager.setCurrentItem(viewPager.getCurrentItem()+1);
                        break;
                    case 2:
                        Bundle bundle1 = msg.getData();
                        break;
                    case 3:
                        break;

                    case 20: {
                        Bundle bundle2 = msg.getData();
                        String info = bundle2.getString("exception");
                        MyToast.showToast(context, info);
                    }
                    break;

                    case 21:

                        int count = myAdapter.getCount();
                        Log.i(TAG, "myAdapter size: " + Integer.toString(count));

                        if (count > 0) {
                            for (int i = 0; i < count; i++) {
                                delPage(0);
                            }
                        }

                        if (nameList.size() > 0)
                            contentList.clear();

                        Log.i(TAG, "name list size: " + Integer.toString(nameList.size()));
                        Log.i(TAG, "urlpic list size: " + Integer.toString(urlList.size()));

                        for (int i = 0; i < nameList.size(); i++) {
                            contentList.add(nameList.get(i));
                            int n = urlList.size();
                            if (n > 0 && i < n) {
                                addUrlIamgePage(urlList.get(i));
                            } else {
                                //  adddefaultPage();
                                addUrlIamgePage(null);
                            }
                        }

                        break;
                    case 22:

                        if (drawableList.size() <= 0)
                            return;

                        for (int k = 0; k < drawableList.size(); k++) {
                            addNewImagePage(drawableList.get(k));
                        }
                        drawableList.clear();
                        break;


                    default:
                        break;
                }
            }catch (Exception e)
            {
              e.printStackTrace();
              MyToast.showToast(context,e.toString());
            }
        }
    }

}
